//
//  KNJTabBaController.m
//  KaNongJia
//
//  Created by RYX on 2018/11/20.
//  Copyright © 2018年 tuobu. All rights reserved.
//

#import "KNJTabBaController.h"
#import "HeaderViewController.h"
#import "MineViewController.h"
#import "BillViewController.h"
#import "BorrowingViewController.h"

@interface KNJTabBaController ()

@property (copy, nonatomic) NSArray *vcArr;
@property (copy, nonatomic) NSArray *titleArr;
@property (copy, nonatomic) NSArray *normalImgArr;
@property (copy, nonatomic) NSArray *selectedImgArr;

@end

@implementation KNJTabBaController

- (NSArray *)vcArr{
    
    if (!_vcArr) {
        
        _vcArr = @[[HeaderViewController class],[BillViewController class],[BorrowingViewController class],[MineViewController class]];
    }
    
    return _vcArr;
}

- (NSArray *)titleArr{
    
    if (!_titleArr) {
        
        _titleArr = @[@"首页",@"账单",@"借款",@"我的"];
    }
    
    return _titleArr;
}

- (NSArray *)normalImgArr{
    
    if (!_normalImgArr) {
        
        _normalImgArr = @[@"icon_tabBar01_normal",@"icon_tabBar02_normal",@"icon_tabBar03_normal",@"icon_tabBar04_normal"];
    }
    
    return _normalImgArr;
}

- (NSArray *)selectedImgArr{
    
    if (!_selectedImgArr) {
        
        _selectedImgArr = @[@"icon_tabBar01_selected",@"icon_tabBar02_selected",@"icon_tabBar03_selected",@"icon_tabBar04_selected"];
    }
    
    return _selectedImgArr;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    for (int i =0; i<self.vcArr.count;i++) {
        
        [self addChildVCWithClass:self.vcArr[i] andTitle:self.titleArr[i] andNormalImg:self.normalImgArr[i] andSelectImg:self.selectedImgArr[i]];
    }
}

- (void)addChildVCWithClass:(Class)class andTitle:(NSString *)title andNormalImg:(NSString *)normalImg andSelectImg:(NSString *)selectedImg{
    
    UIViewController *VC = [[class alloc] init];
    VC.title = title;
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:VC];
    [nav.navigationBar navBarBackGroundColor:NAVCOLOR image:nil isOpaque:YES];
    nav.tabBarItem.title = title;
    [nav.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"PingFang-SC-Medium" size:18.0],NSForegroundColorAttributeName:[UIColor whiteColor]}];
    
    [nav.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor grayColor]} forState:UIControlStateNormal];
    [nav.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:NAVCOLOR} forState:UIControlStateSelected];
    
    [nav.navigationBar setTintColor:[UIColor whiteColor]];
    nav.tabBarItem.image = [[UIImage imageNamed:normalImg] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    nav.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImg] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [self addChildViewController:nav];
    
}

@end
